package com.wsy.controller;

import com.github.pagehelper.PageInfo;
import com.wsy.entity.BookInfo;
import com.wsy.entity.Orders;
import com.wsy.service.BookInfoService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RequestMapping("bookinfo")
@RestController
public class BookInfoController {
    @Resource
    BookInfoService bookInfoService;

    @RequestMapping("select")
    public PageInfo<BookInfo> select(Integer pageNum, Integer pageSize){
        return bookInfoService.select(pageNum, pageSize);
    }

    @RequestMapping("selectById")
    public List<BookInfo> selectById(Integer id) {
        return bookInfoService.selectById(id);
    }

    @RequestMapping("addOrders")
    public int addOrders(Orders orders){
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        orders.setCreateTime(sdf.format(date));
        bookInfoService.addOrders(orders);
        return orders.getOrderId();
    }

    @RequestMapping("selOrders")
    public List<Orders> selOrders(String oid){
        return bookInfoService.selOrders(oid);
    }

    @RequestMapping("updOrderPay")
    public int updOrderPay(String oid,String addressId){
        return bookInfoService.updOrderPay(oid, addressId);
    }

    @RequestMapping("allOrders")
    public List<Orders> selUserOrders(String userId){
        return bookInfoService.selUserOrders(userId);
    }


}
